<template>
    <view class="content">
        <u-cell-group>
            <u-cell title="客户名称" :value="detail.business.nickname"></u-cell>
			<u-cell title="联系方式" :value="detail.business.mobile"></u-cell>
            <u-cell title="性别" v-if="detail.gender == 0" value="保密"></u-cell>
            <u-cell title="性别" v-else-if="detail.business.gender == 1" value="男"></u-cell>
            <u-cell title="性别" v-else-if="detail.business.gender == 2" value="女"></u-cell>
            <u-cell title="客户来源" :value="detail.business.source_text"></u-cell>
			<u-cell title="订单内容">
				<view slot="value" class="u-slot-title">
					<view class="item" v-for="item in detail.productLIst" :key="item.id">
						<view class="item_text">
							<text>商品名称：{{item.product_text}}</text>
							<text>商品价格：{{item.price}}元</text>
							<text>商品数量：{{item.pronum}}</text>					
						</view>
						<u--image :showLoading="true" :src="item.products.cover_cdn" width="100px" height="50px" @click="click"></u--image>
					</view>
				</view>
			</u-cell>
            <u-cell title="订单总额" :value="detail.amount+'元'"></u-cell>
            <u-cell title="下单时间" :value="format(detail.createtime)"></u-cell>
            <u-cell title="地址" :value="detail.address.address_text"></u-cell>
        </u-cell-group>
        
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    data() {
        return {
			LoginUser:{},
            id: 0,
            detail: {
                source: {
                    name: ''
                }
            },
            RegionShow: false
        }
    },
    onLoad(options)
    {
		this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}
		
        this.id = options.orderid ? options.orderid : 0

        this.getInfoData()
    },
    methods: {
		 // 转换时间戳为日期格式方法
		    add(m) {
		      return m < 10 ? "0" + m : m;
		    },
		    format(time) {
		      //shijianchuo是整数，否则要parseInt转换
		      var time = new Date(time);
		      var y = time.getFullYear();
		      var m = time.getMonth() + 1;
		      var d = time.getDate();
		      var h = time.getHours();
		      var mm = time.getMinutes();
		      var s = time.getSeconds();
		      return (
		        y +
		        "-" +
		        this.add(m) +
		        "-" +
		        this.add(d) +
		        " " +
		        this.add(h) +
		        ":" +
		        this.add(mm) +
		        ":" +
		        this.add(s)
		      );
		    },
        async getInfoData()
        {
			let data={
				orderid:this.id,
				Adminid:this.LoginUser.id
			}
            let result = await this.$u.api.order.getProinfo(data)

            if(result.code === 0)
            {
                this.$refs.uToast.show({
                    type:'error',
                    message:result.msg,
                    complete:() => {
                        this.$u.route({
                            type:'redirectTo',
                            url:'/packageB/proorder/index'
                        })
                    }
                })

                return false
            }else{
                this.detail = result.data
            }
        }
    },
}
</script>
<style>
	.item{
		display: flex;
	}
	.item_text{
		display: flex;
		flex-direction: column;
		font-size: 12px
	}
</style>